*==============================================================================*
*                                figure 5:                                     *
*     used versus new emission rates for tier 2 exhaust standards, 2000-2010   *
*==============================================================================*
* this table uses colorado IM240 data


u "dataSTATA/combined/combined_smogcheck_colorado.dta", clear
merge m:1 vin10 using "dataSTATA/concordances/vin_linkedto_newcars.dta", keep(3) nogen


* non-missing new vehicle emissions tests for all pollutants including CO2 
keep if emissions_new_CO < . & emissions_new_HC < . & emissions_new_NOX < . & emissions_new_CO2 < .

* non-missing used vehicle emissions tests for all pollutants including CO2
keep if emissions_used_CO < . & emissions_used_HC < . & emissions_used_NOX < . & emissions_used_CO2 < .

* 2.2% of sample has a zero reading for some pollutant.
egen rowmin = rowmin(emissions_used_* emissions_new_*)
drop if rowmin <= 0
drop rowmin


foreach v of varlist emissions_used_* emissions_new_* {
	g ln`v' = ln(`v')
}

mat M = J(5,60,.)

foreach p in CO HC NOX CO2 {
	qui su lnemissions_new_`p', d
	binscatter lnemissions_used_`p'   lnemissions_new_`p' if fulltest == 1, ///
		graphr(color(white)) yscale(noline) ///
		xtit("Log New Vehicle Emissions") ytit("Log Used Vehicle Emissions") ///
		subtit("`p'")
	graph save "results/figures/f5_binscatter_tier2/`p'.gph", replace
	graph export "results/figures/f5_binscatter_tier2/`p'.wmf", replace
	graph export "$overleaf/figures/f5_binscatter_tier2/`p'.eps", replace
}


